package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.ruoyi.project.mahjong.domain.TMember;
import com.ruoyi.project.mahjong.service.ITMemberService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.TReservation;
import com.ruoyi.project.mahjong.service.ITReservationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 会员预约Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/mahjong/reservation")
public class TReservationController extends BaseController
{
    @Autowired
    private ITReservationService tReservationService;
    @Autowired
    private ITMemberService tMemberService;
    /**
     * 查询会员预约列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TReservation tReservation)
    {
        startPage();
        List<TReservation> list = tReservationService.selectTReservationList(tReservation);
        return getDataTable(list);
    }
    @GetMapping("/listalluser")
    public AjaxResult listalluser( )
    {
        List<TMember> list = tMemberService.selectTMemberList(new TMember());
        return AjaxResult.success(list);
    }

    /**
     * 导出会员预约列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:export')")
    @Log(title = "会员预约", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TReservation tReservation)
    {
        List<TReservation> list = tReservationService.selectTReservationList(tReservation);
        ExcelUtil<TReservation> util = new ExcelUtil<TReservation>(TReservation.class);
        return util.exportExcel(list, "reservation");
    }

    /**
     * 获取会员预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tReservationService.selectTReservationById(id));
    }

    /**
     * 新增会员预约
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:add')")
    @Log(title = "会员预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReservation tReservation)
    {
        return toAjax(tReservationService.insertTReservation(tReservation));
    }

    /**
     * 修改会员预约
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:edit')")
    @Log(title = "会员预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReservation tReservation)
    {
        return toAjax(tReservationService.updateTReservation(tReservation));
    }

    /**
     * 删除会员预约
     */
    @PreAuthorize("@ss.hasPermi('mahjong:reservation:remove')")
    @Log(title = "会员预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tReservationService.deleteTReservationByIds(ids));
    }
}
